<template>
  <div class="login_panel">
    <div class="title" data-type='["Vue3.Django System"]'></div>
    <el-tabs type="border-card" stretch v-model="currentTab">
      <el-tab-pane name="account">
        <template #label>
          <el-icon><User /></el-icon>
          <span class="span">Login</span>
        </template>
        <login-account ref="accountRef" />
      </el-tab-pane>
      <el-tab-pane name="phone">
        <template #label>
          <el-icon><Iphone /></el-icon>
          <span class="span"> Register</span>
        </template>
        <login-phone ref="phoneRef" />
      </el-tab-pane>
    </el-tabs>

    <div class="account-control">
      <el-checkbox v-model="isKeepPassword">Remember password</el-checkbox>
      <el-link type="primary">Forget password</el-link>
    </div>

    <el-button type="primary" class="login-btn" @click="handleLoginClick"
      >login</el-button
    >
  </div>
</template>

<script setup lang="ts">
import { onMounted, ref } from 'vue'
import LoginAccount from './login-account.vue'
import LoginPhone from './login-phone.vue'
import txtAni from '@/utils/text-type'

onMounted(() => {
  txtAni('title')
})

const isKeepPassword = ref(true)
const accountRef = ref<InstanceType<typeof LoginAccount>>()
const phoneRef = ref<InstanceType<typeof LoginPhone>>()
const currentTab = ref('account')

const handleLoginClick = () => {
  if (currentTab.value === 'account') {
    accountRef.value?.loginAction(isKeepPassword.value)
  } else {
    console.log('phoneRef调用loginAction')
  }
}
</script>

<style scoped lang="less">
.login_panel {
  margin-top: -250px;
  width: 320px;
  .title {
    color: #4f00b5;
    text-align: center;
    font-size: 20px;
    font-weight: 700;
  }
  .span {
    margin-left: 5px;
  }
  .account-control {
    margin-top: 10px;
    display: flex;
    justify-content: space-between;
  }

  .login-btn {
    width: 100%;
    margin-top: 10px;
  }
}
</style>
